package com.marmot.cloud.framework.admin.controller;

import cn.hutool.json.JSONUtil;
import com.marmot.cloud.framework.admin.dto.MenuDTO;
import com.marmot.cloud.framework.biz.po.Menu;
import com.marmot.cloud.framework.biz.service.MenuJpaService;
import com.marmot.cloud.framework.cache.redis.manager.RedisManager;
import com.marmot.cloud.framework.core.controller.BaseController;
import com.marmot.cloud.framework.core.pager.PageHelper;
import com.marmot.cloud.framework.core.response.PageData;
import com.marmot.cloud.framework.core.response.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "菜单接口", description = "菜单CRUD基本情况")
@Slf4j
@RestController
@RequestMapping("/menu")
@RequiredArgsConstructor
public class MenuController extends BaseController {
    private final MenuJpaService menuJpaService;
    private final RedisManager redisManager;

    @Operation(summary = "根据条件查询菜单信息", description = "查询列表数据，支持分页排序")
    @PostMapping("/list")
    public R<PageData<MenuDTO>> list(@RequestBody PageHelper<Menu> query) {
        log.info("[Find Info] Request Params:{}", query.toString());
        PageData<Menu> data = this.menuJpaService.findExample(query);
        redisManager.setValue("menu::list", data);

        return R.success(data.converter(MenuDTO.class));
    }


    // ==================================private===================================


}
